home *** CD-ROM | disk | FTP | other *** search
/ United Public Domain Gold 2 / United Public Domain Gold 2.iso / utilities / pu660.dms / pu660.adf / Vmem / vmem.h < prev    next >
C/C++ Source or Header  |  1991-12-19  |  8KB  |  274 lines

  1. /*
  2. ** VMEM.H - header file for VMEM
  3. **
  4. ** Version 0.1 ©1990 by Edward Hutchins
  5. ** Based in part on the SetCPU program by Dave Haynie
  6. ** Authors:
  7. **
  8. **    Edward Hutchins: eah1@cec1.wustl.edu
  9. **    Loren Rittle: l-rittle@uiuc.edu
  10. **
  11. ** Revisions:
  12. ** 12/19/91 code released as freeware under the GNU general public license - Ed.
  13. **
  14. **    This program is free software; you can redistribute it and/or modify
  15. **    it under the terms of the GNU General Public License as published by
  16. **    the Free Software Foundation; either version 1, or (at your option)
  17. **    any later version.
  18. **
  19. **    This program is distributed in the hope that it will be useful,
  20. **    but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. **    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  22. **    GNU General Public License for more details.
  23. **
  24. **    You should have received a copy of the GNU General Public License
  25. **    along with this program; if not, write to the Free Software
  26. **    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  27. */
  28.  
  29. #include <stdio.h>
  30. #include <exec/types.h>
  31. #include <exec/exec.h>
  32. #include <exec/execbase.h>
  33. #include <exec/tasks.h>
  34. #include <exec/memory.h>
  35. #include <libraries/dos.h>
  36. #include <devices/timer.h>
  37. #include <graphics/gfx.h>
  38. #include <graphics/rastport.h>
  39. #include <intuition/intuition.h>
  40. #include <proto/all.h>
  41.  
  42. /*
  43. ** external declarations for the assembly routines
  44. */
  45.  
  46. IMPORT VOID SetCRP(ULONG *);
  47. IMPORT VOID GetCRP(ULONG *);
  48. IMPORT VOID SetTC(ULONG);
  49. IMPORT ULONG GetTC(VOID);
  50. IMPORT VOID SetCACR(ULONG);
  51. IMPORT ULONG GetCACR(VOID);
  52. IMPORT ULONG GetCPUType(VOID);
  53. IMPORT ULONG GetMMUType(VOID);
  54. IMPORT ULONG GetFPUType(VOID);
  55. IMPORT VOID InsertFaultHandler(VOID);
  56.  
  57. /*
  58. ** Define all bit components used for manipulation of the Cache Control
  59. ** Register.
  60. */
  61.  
  62. #define CACR_INST    (1L<<0)
  63. #define CACR_DATA    (1L<<8)
  64.  
  65. #define CACR_WALLOC    5
  66. #define CACR_BURST    4
  67. #define CACR_CLEAR    3
  68. #define CACR_ENTRY    2
  69. #define CACR_FREEZE    1
  70. #define CACR_ENABLE    0
  71.  
  72. /*
  73. ** Define important bits used in various MMU registers.
  74. */
  75.  
  76. /*
  77. ** Here are the CRP definitions.  The CRP register is 64 bits long, but
  78. ** only the first 32 bits are control bits, the next 32 bits provide the
  79. ** base address of the table.
  80. */
  81.  
  82. #define    CRP_UPPER        (1L<<31)                    /* Upper/lower limit mode */
  83. #define CRP_LIMIT(x)    ((ULONG)((x)&0x7fff)<<16)    /* Upper/lower limit value */
  84. #define CRP_SG            (1L<<9)                        /* Indicates shared space */
  85. #define CRP_DT_INVALID    0x00                        /* Invalid root descriptor */
  86. #define    CRP_DT_PAGE        0x01                        /* Fixed offset, auto-genned */
  87. #define CRP_DT_V4BYTE    0x02                        /* Short root descriptor */
  88. #define    CRP_DT_V8BYTE    0x03                        /* Long root descriptor */
  89. #define CRP_DT_MASK        0x03
  90.  
  91. /*
  92. ** Here are the TC definitions.  The TC register is 32 bits long.
  93. */
  94.  
  95. #define    TC_ENB            (1L<<31)                    /* Enable the MMU */
  96. #define    TC_SRE            (1L<<25)                    /* For separate Supervisor */
  97. #define    TC_FCL            (1L<<24)                    /* Use function codes? */
  98. #define    TC_PS(x)        ((ULONG)((x)&0x0f)<<20)        /* Page Size */
  99. #define TC_IS(x)        ((ULONG)((x)&0x0f)<<16)        /* Initial Shift */
  100. #define    TC_TIA(x)        ((ULONG)((x)&0x0f)<<12)        /* Table level A index */
  101. #define    TC_TIB(x)        ((ULONG)((x)&0x0f)<<8)        /* Table level B index */
  102. #define TC_TIC(x)        ((ULONG)((x)&0x0f)<<4)        /* Table level C index */
  103. #define    TC_TID(x)        ((ULONG)((x)&0x0f)<<0)        /* Table level D index */
  104.  
  105. /*
  106. ** Here are the page descriptor definitions, for short descriptors only,
  107. ** since that's all I'm using at this point.
  108. */
  109.  
  110. #define    PD_ADDR(x)        ((ULONG)(x)&~0x0F)            /* Translated Address */
  111. #define PD_ADDR_MASK    (0xFFFFFFF0)                /* address bits */
  112. #define    PD_WP            (1<<2)                        /* Write protect it! */
  113. #define PD_USED            (1<<3)                        /* page referenced */
  114. #define PD_MOD            (1<<4)                        /* page "dirty" */
  115. #define PD_CI            (1<<6)                        /* cache inhibit */
  116. #define PD_DT_INVALID    0x00                        /* Invalid root descriptor */
  117. #define    PD_DT_PAGE        0x01                        /* Fixed offset, auto-gen */
  118. #define PD_DT_V4BYTE    0x02                        /* Short root descriptor */
  119. #define    PD_DT_V8BYTE    0x03                        /* Long root descriptor */
  120. #define PD_DT_MASK        0x03                        /* DT mask */
  121.  
  122. /* short page descriptor format */
  123. typedef ULONG PD_SHORT;
  124. typedef PD_SHORT *PPD_SHORT;
  125.  
  126. /* long page descriptor format */
  127. typedef struct
  128. {
  129.     UWORD                Limit;
  130.     UWORD                Status;
  131.     ULONG                Address;
  132. } PD_LONG;
  133. typedef PD_LONG *PPD_LONG;
  134.  
  135. /* page frame descriptor stuff (for the ageing table) */
  136. typedef struct
  137. {
  138.     UWORD                Age;                        /* page age in daemon ticks */
  139.     UWORD                PageIndex;                    /* index into PageTable */
  140. } FRAME_DESC;
  141. typedef FRAME_DESC *PFRAME_DESC;
  142.  
  143. /* maximum age allowed by law */
  144. #define AGE_MAX 0xFFFF
  145.  
  146. /* weighted average age, since dirty pages cost twice what clean ones do */
  147. #define WAGE(p) (((PageTable[(p)->PageIndex])&PD_MOD)?((p)->Age/2):((p)->Age))
  148.  
  149. /*
  150. ** Here's the FASTROM support stuff.
  151. */
  152.  
  153. #define ROMBASE            0x00FC0000
  154. #define ROMSIZE            0x00040000
  155.  
  156. /*
  157. ** Bus Error exception stack frames
  158. */
  159.  
  160. /* fault format numbers are in VectorOffset */
  161. #define SF_FORMAT_MASK    0xF000
  162. #define SSF_SIZE        0x20
  163. #define SSF_FORMAT        0xA000
  164. #define LSF_SIZE        0x5C
  165. #define LSF_FORMAT        0xB000
  166.  
  167. /* short bus cycle fault (16 words) - format $a */
  168. typedef struct
  169. {
  170.     UWORD                StatusReg;
  171.     CPTR                PC;
  172.     UWORD                VectorOffset;    /* bits 12-15 are the frame ID (1010) */
  173.     UWORD                InternReg1;
  174.     UWORD                SpecialStatusReg;
  175.     UWORD                InstPipeC;
  176.     UWORD                InstPipeB;
  177.     CPTR                DataCycleFaultAddr;
  178.     UWORD                InternReg2[2];
  179.     ULONG                DataOutputBuffer;
  180.     UWORD                InternReg3[2];
  181. } ShortBusFault;
  182. typedef ShortBusFault *PShortBusFault;
  183.  
  184. /* long bus cycle fault (46 words) - format $b */
  185. typedef struct
  186. {
  187.     UWORD                StatusReg;
  188.     CPTR                PC;
  189.     UWORD                VectorOffset;    /* bits 12-15 are the frame ID (1010) */
  190.     UWORD                InternReg1;
  191.     UWORD                SpecialStatusReg;
  192.     UWORD                InstPipeC;
  193.     UWORD                InstPipeB;
  194.     CPTR                DataCycleFaultAddr;
  195.     UWORD                InternReg2[2];
  196.     ULONG                DataOutputBuffer; /* same as short frame to here */
  197.     UWORD                InternReg3[4];
  198.     CPTR                StageBAddress;
  199.     UWORD                InternReg4[2];
  200.     ULONG                DataInputBuffer;
  201.     UWORD                InternReg5[3];
  202.     UWORD                InternalInformation;    /* version # in bits 12-15 */
  203.     UWORD                InternReg6[18];
  204. } LongBusFault;
  205. typedef LongBusFault *PLongBusFault;
  206.  
  207. /* special status bits */
  208. #define SSTAT_FC        0x8000    /* fault on stage C of the instruction pipe */
  209. #define SSTAT_FB        0x4000    /* fault on stage B */
  210. #define SSTAT_RC        0x2000    /* stage C re-run */
  211. #define SSTAT_RB        0x1000    /* stage B re-run */
  212. #define SSTAT_DF        0x0100    /* data fault */
  213. #define SSTAT_RM        0x0080    /* read-modify-write cycle */
  214. #define SSTAT_RW        0x0040    /* read/write indicator */
  215. #define SSTAT_SIZE_MASK    0x0030    /* size of data transfer */
  216.  
  217. /* the exception could be either one of these */
  218. typedef union
  219. {
  220.     ShortBusFault        S;
  221.     LongBusFault        L;
  222. } BusFault;
  223. typedef BusFault *PBusFault;
  224.  
  225. /*
  226. ** FaultNode - a recorded page fault
  227. */
  228.  
  229. typedef struct
  230. {
  231.     struct MinNode        Next;                        /* page fault list */
  232.     ULONG                OldRegs[15];                /* d0-d7/a0-a6 */
  233.     ULONG                OldUSP;                        /* previous USP */
  234.     struct Task            *FaultedTask;                /* the task with the fault */
  235.     UBYTE                RestartSigNum;                /* signal bit number */
  236.     UBYTE                Pad[3];                        /* longword padding */
  237.     BusFault            Fault;                        /* copied fault */
  238. } FaultNode;
  239. typedef FaultNode *PFaultNode;
  240.  
  241. /*
  242. ** This is what a fault node contains:
  243. **
  244. **            low memory
  245. ** |----------------------------|    start of FaultNode
  246. ** |FaultNode                    |    real fault frame copied from system stack
  247. ** |----------------------------|    end of fake user stack
  248. ** |////////////////////////////|    padding (hopefully)
  249. ** |/// Task Context saved by //|
  250. ** |///// Signal() or Wait() ///|
  251. ** |----------------------------|    this is where the fake USP is left pointing
  252. ** |///// return address ///////|    fake return address pointing to RestartHandler
  253. ** |----------------------------|    top of fake user stack
  254. **            high memory
  255. */
  256.  
  257. /* allocate this much space for the FaultNode and the fake user stack */
  258. #define FAULTNODE_SIZE 0x400
  259.  
  260. /*
  261. ** Ageing timer stuff
  262. */
  263.  
  264. typedef struct timerequest TIMER_REQ;
  265. typedef TIMER_REQ *PTIMER_REQ;
  266.  
  267. /*
  268. ** function prototypes
  269. */
  270.  
  271. extern struct Window *OpenScrn(WORD w, WORD h, WORD d, ULONG IDCMP, ULONG Flags);
  272. extern void CloseScrn(struct Window * window);
  273.  
  274.